import StartProcess from '@/apis/StartProcess.js'
import { goTo } from '@/utils/goTo'
export default {
  name: 'ApprovalButton',
  props: ['procInfo', 'approvalType', 'warn'],
  data() {
    return {
      procType: {
        leave: '请假',
        reimbursement: '报销',
        fillClock: '补卡',
        adjustJob: '调岗',
        adjustSalary: '调薪',
        overtime: '加班',
        travel: '出差',
        destroy: '销假、销出差',
        separation: '离职',
        positive: '转正',
      },
      procData: {
        departmentName: this.$store.state.postInfo.department,
        jobNumber: this.$store.state.userInfo.jobNumber,
        processKey: this.approvalType,
        processName: '',
        username: this.$store.state.userInfo.name,
      },
    }
  },
  methods: {
    createANewApproval() {
      if (this.warn) {
        this.$toast(this.warn)
        return
      }
      uni.showLoading({
        title: '加载中',
      })
      this.procData['processName'] = this.procType[this.approvalType]
      this.pushAProcText(this.approvalType)
      StartProcess(this.procData, this.$store.state.authorization).then(
        (res) => {
          // console.log(res)
          if (res.data.flag) {
            uni.hideLoading()
            this.$toast('申请成功')
            setTimeout(() => {
              goTo('/pages/main/index')
            }, 600)
          }
        }
      )
    },
    pushAProcText(textType) {
      const type = textType[0].toUpperCase() + textType.slice(1)
      this.procData['proc' + type] = this.procInfo
    },
  },
}
